<template>
    <div>
        <h1>权益显示</h1>      
        <a href="/QYAdd">权益添加</a>
        <table class="table">
            <thead>
                <tr>
                    <td>权益编号</td>
                    <td>权益名称</td>
                    <td>权益状态</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody v-for="a in data">
                <tr>
                    <td>{{a.QYId}}</td>
                    <td>{{a.QYName}}</td>
                    <td>{{a.QYState?"启用":"禁用"}}</td>
                    <td>
                        <input type="button" value="修改状态" @click="UpdState(a.QYId)">
                        <input type="button" value="逻辑删除" @click="Del(a.QYId)">
                        <input type="button" value="修改" @click="Fan(a.QYId)">
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import { ref ,onMounted} from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
onMounted(()=>{
    Show()

})

const data = ref([{
   "QYId": 0,
    "QYName": "",
    "QYState": true,
    "QYIsDelete": true
}])




const Show=()=>{
    axios.get('https://localhost:7174/api/QY/ShowMember').then(res=>{
        data.value = res.data
    })
}

const UpdState = (e:any)=>{
    if(confirm('确定修改吗？')){
        axios.get('https://localhost:7174/api/QY/UpdState',{params:{QYId:e}}).then(res=>{
            if(res.data>0){
                alert('修改成功');
                Show()
            }
            else{
                alert('修改失败')
            }
        })
    }
    
}
const Del = (e:any)=>{
    if(confirm('确定删除吗？')){
        axios.get('https://localhost:7174/api/QY/Del',{params:{QYId:e}}).then(res=>{
            if(res.data>0){
                alert('删除成功');
                Show()
            }
            else{
                alert('删除失败')
            }
        })
    }
    
}


const router = useRouter();
const Fan=(a:any)=>{
    router.push({path:"/QYUpd",query:{QYId:a}})
}

</script>

<style scoped>

</style>